package main

import (
	"crypto/ecdsa"
	"fmt"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/ethereum/go-ethereum/crypto"
)

func main() {
	privateKey, _ := crypto.GenerateKey()
	// 私钥
	fmt.Println("private key:", hexutil.Encode(crypto.FromECDSA(privateKey)))

	// 私钥 推导公钥
	publicKey, _ := privateKey.Public().(*ecdsa.PublicKey)
	fmt.Println("public key: ", hexutil.Encode(crypto.FromECDSAPub(publicKey)))

	// 推导账户地址
	address := crypto.PubkeyToAddress(*publicKey)
	fmt.Println("address:", address.Hex())
}
